import 'package:flutter/material.dart';
import 'package:opene/app_theme.dart';
import 'package:opene/app_utils.dart';
import 'package:opene/base/scan_code.dart';
import 'package:opene/ui/returns/returnsmodel.dart';

class NewPreprocessDialog extends StatefulWidget {
  String processType;

  NewPreprocessDialog({this.processType});

  @override
  _NewPreprocessDialogState createState() => _NewPreprocessDialogState(processType: this.processType);
}

class _NewPreprocessDialogState extends State<NewPreprocessDialog> {
  final TextEditingController textEditingController = TextEditingController();
  String processType;
  String hint;
  _NewPreprocessDialogState({this.processType});

  @override
  Widget build(BuildContext context) {
    return Dialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12.0),
      ),
      child: Padding(
        padding: const EdgeInsets.only(top: 15, left: 15, right: 15),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Text("Tips", style: MyAppTheme.title),
            SizedBox(height: 2.0),
            Text(Utils.getStringisEmpty(processType), style: MyAppTheme.text),
            SizedBox(height: 2.0),
            Container(
              margin: const EdgeInsets.only(left: 0, top: 0, right: 0, bottom: 0),
              width: double.infinity,
              child: ConstrainedBox(
                constraints: BoxConstraints(maxHeight: 35),
                child: TextField(
                  controller: textEditingController,
                  textInputAction: TextInputAction.search,
                  onSubmitted: (String text) {
                    print('Searching for $text');
                    if (Utils.isEmpty(text)) {
                      return;
                    }
                  },
                  // autofocus: true,
                  decoration: InputDecoration(
                    suffixIcon: IconButton(
                      padding: EdgeInsets.all(2.0),
                      icon: Icon(
                        Icons.qr_code_scanner,
                        size: 28,
                        color: MyAppTheme.nearlyBlue,
                      ),
                      onPressed: () {
                        // requestPermissions();
                        // Utils.scanBarcode(context);
                        Navigator.of(context).push(MaterialPageRoute(builder: (context) {
                          return ScanCode();
                        })).then((text) {
                          if (text == null) {
                            return;
                          }
                          setState(() {
                            textEditingController.text = text;
                          });
                          print(text); //拿到扫描结果
                        });
                      },
                    ),
                    border: OutlineInputBorder(
                      borderSide: BorderSide(
                        color: MyAppTheme.nearlyBlue,
                      ),
                      borderRadius: const BorderRadius.all(Radius.circular(20.0)),
                    ),
                    enabledBorder: OutlineInputBorder(
                      borderSide: BorderSide(color: MyAppTheme.nearlyBlue),
                      // 设置焦点之外的边框颜色
                      borderRadius: const BorderRadius.all(Radius.circular(20.0)),
                    ),
                    focusedBorder: OutlineInputBorder(
                      borderSide: BorderSide(color: MyAppTheme.nearlyBlue),
                      // 设置焦点时的边框颜色
                      borderRadius: const BorderRadius.all(Radius.circular(20.0)),
                    ),
                    hintText: "scan fba label",
                    filled: true,
                    fillColor: MyAppTheme.white,
                    //隐藏下划线
                    //border: InputBorder.none,
                    hintStyle: TextStyle(color: Colors.grey),
                    contentPadding: const EdgeInsets.symmetric(vertical: 0, horizontal: 15),
                  ),
                ),
              ),
            ),
            Text(Utils.getStringisEmpty(hint), style: MyAppTheme.text),
            SizedBox(height: 16.0),
            Row(
              children: <Widget>[
                Expanded(
                    flex: 1,
                    child: FlatButton(
                      child: Text(
                        'Cancel',
                        style: MyAppTheme.title,
                      ),
                      onPressed: () {
                        Navigator.of(context).pop(false);
                      },
                    )),
                Expanded(
                    flex: 1,
                    child: FlatButton(
                      child: Text(
                        'Confirm',
                        style: MyAppTheme.titlenearlyBlue16,
                      ),
                      onPressed: () {
                        Navigator.of(context).pop(true);
                      },
                    )),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
class FinalProcessTrkTypeDialog extends StatefulWidget {
  String processType;
  FinalProcessTrk finalProcessTrk;

  FinalProcessTrkTypeDialog({this.processType,this.finalProcessTrk});

  @override
  _FinalProcessTrkTypeDialogState createState() => _FinalProcessTrkTypeDialogState(processType: this.processType,finalProcessTrk: this.finalProcessTrk);
}

class _FinalProcessTrkTypeDialogState extends State<FinalProcessTrkTypeDialog> {
  String processType;
  FinalProcessTrk finalProcessTrk;
  _FinalProcessTrkTypeDialogState({this.processType,this.finalProcessTrk});

  @override
  Widget build(BuildContext context) {
    return Dialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12.0),
      ),
      child: Padding(
        padding: const EdgeInsets.only(top: 15, left: 15, right: 15),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Text("Tips", style: MyAppTheme.title),
            SizedBox(height: 2.0),
            Text(Utils.getStringisEmpty(processType), style: MyAppTheme.text),
            Visibility(
                visible: Utils.isEmpty(finalProcessTrk.notes)?false:true,
                child: Row(children: [

                  Text("Notes: ", style: MyAppTheme.text),
                  Text(Utils.getStringisEmpty(finalProcessTrk.notes), style: MyAppTheme.textred14),
                ],)),
            Visibility(
                visible: Utils.getIntegerisEmpty(finalProcessTrk.retape) == 1?true:false,
                child:  Text("Need to be retaped", style: MyAppTheme.textred14),),
            SizedBox(height: 16.0),
            Row(
              children: <Widget>[
                Expanded(
                    flex: 1,
                    child: FlatButton(
                      child: Text(
                        'Got It',
                        style: MyAppTheme.titlenearlyBlue16,
                      ),
                      onPressed: () {
                        Navigator.of(context).pop(true);
                      },
                    )),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

class FinalProcessTrkSkuTypeDialog extends StatefulWidget {
  @override
  _FinalProcessTrkSkuTypeDialogState createState() => _FinalProcessTrkSkuTypeDialogState();
}

class _FinalProcessTrkSkuTypeDialogState extends State<FinalProcessTrkSkuTypeDialog> {
  @override
  Widget build(BuildContext context) {
    return Dialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12.0),
      ),
      child: Padding(
        padding: const EdgeInsets.only(top: 15, left: 15, right: 15),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Text("Tips", style: MyAppTheme.title),
            SizedBox(height: 2.0),
            Text("SKU QTY more than 1", style: MyAppTheme.text),
            SizedBox(height: 16.0),
            Row(
              children: <Widget>[
                Expanded(
                    flex: 1,
                    child: FlatButton(
                      child: Text(
                        'Cancel',
                        style: MyAppTheme.titlenearlyBlue16,
                      ),
                      onPressed: () {
                        Navigator.of(context).pop(false);
                      },
                    )),
                Expanded(
                    flex: 1,
                    child: FlatButton(
                      child: Text(
                        'Confirm',
                        style: MyAppTheme.titlenearlyBlue16,
                      ),
                      onPressed: () {
                        Navigator.of(context).pop(true);
                      },
                    )),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

class BounceDialog extends StatefulWidget {
  String processType;

  BounceDialog({this.processType});

  @override
  _BounceDialogState createState() => _BounceDialogState(processType: this.processType);
}

class _BounceDialogState extends State<BounceDialog> {
  String processType;

  _BounceDialogState({this.processType});

  @override
  Widget build(BuildContext context) {
    return Dialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12.0),
      ),
      child: Padding(
        padding: const EdgeInsets.only(top: 15, left: 15, right: 15),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Text("Tips", style: MyAppTheme.title),
            SizedBox(height: 2.0),
            Text(Utils.getStringisEmpty(processType) == "D" ? "Destroy \n (put in a lBLPN first)" : "Putaway \n (put in a lBLPN first)", style: MyAppTheme.text),
            SizedBox(height: 16.0),
            Image.asset(
              Utils.getStringisEmpty(processType) == "D" ? 'assets/images/ic_bounce_destroy.png' : 'assets/images/ic_bounce_putaway.png',
              width: 100,
              height: 100,
            ),
            Row(
              children: <Widget>[
                Expanded(
                    flex: 1,
                    child: FlatButton(
                      child: Text(
                        'Got It',
                        style: MyAppTheme.titlenearlyBlue16,
                      ),
                      onPressed: () {
                        Navigator.of(context).pop(true);
                      },
                    )),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

class FinalProcessDetailDialog extends StatefulWidget {
  String batchNo;
  List<FinalProcessDetail> tallyDetails = new List();

  FinalProcessDetailDialog({this.batchNo, this.tallyDetails});

  @override
  _FinalProcessDetailDialogState createState() => _FinalProcessDetailDialogState(batchNo: batchNo, tallyDetails: this.tallyDetails);
}

class _FinalProcessDetailDialogState extends State<FinalProcessDetailDialog> {
  String batchNo;
  List<FinalProcessDetail> tallyDetails = new List();

  _FinalProcessDetailDialogState({this.batchNo, this.tallyDetails});

  @override
  Widget build(BuildContext context) {
    return Dialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12.0),
      ),
      child: Padding(
        padding: const EdgeInsets.only(top: 15, left: 15, right: 15),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Text("Detail(${batchNo})", style: MyAppTheme.title),
            SizedBox(height: 16.0),
            Row(
              children: [
                Expanded(
                    flex: 2,
                    child: Text(
                      'LPN',
                      style: MyAppTheme.text,
                    )),
                Expanded(flex: 1, child: Text('PCS', style: MyAppTheme.text)),
                Expanded(flex: 1, child: Text('Pending', style: MyAppTheme.text)),
                SizedBox(width: 20.0),
              ],
            ),
            Flexible(
              fit: FlexFit.loose,
              child: setListView(),
            ),
            // Expanded(
            //   child: setListView(),
            // ),
            // setListView(),
            // SizedBox(height: 5.0),
            Row(
              children: <Widget>[
                Expanded(
                    flex: 1,
                    child: FlatButton(
                      child: Text(
                        'Close',
                        style: MyAppTheme.title,
                      ),
                      onPressed: () {
                        Navigator.of(context).pop();
                      },
                    )),
              ],
            ),
          ],
        ),
      ),
    );
  }

  ListView setListView() {
    return ListView.builder(
      shrinkWrap: true,
      // physics: NeverScrollableScrollPhysics(),
      itemCount: tallyDetails == null ? 0 : tallyDetails.length,
      itemBuilder: (context, index) {
        FinalProcessDetail tallyDetail = tallyDetails[index];
        return Column(
          children: [
            Row(
              children: [
                Expanded(
                    flex: 2,
                    child: Text(
                      Utils.getStringisEmpty(tallyDetail.lpn),
                      style: MyAppTheme.text,
                    )),
                Expanded(flex: 1, child: Text('${tallyDetail.pcs}', style: MyAppTheme.text)),
                Expanded(flex: 1, child: Text('${tallyDetail.pending}', style: MyAppTheme.text)),
              ],
            ),
            Divider(),
          ],
        );
      },
    );
  }
}


class PreprocessSucceedDialog extends StatefulWidget {

  @override
  _PreprocessSucceedDialogState createState() => _PreprocessSucceedDialogState();
}

class _PreprocessSucceedDialogState extends State<PreprocessSucceedDialog> {

  @override
  Widget build(BuildContext context) {
    return Dialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12.0),
      ),
      child: Padding(
        padding: const EdgeInsets.only(top: 15, left: 15, right: 15),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Text("Tips", style: MyAppTheme.title),
            SizedBox(height: 16.0),
            Text("Submit successfully", style: MyAppTheme.text),
            Row(
              children: <Widget>[
                Expanded(
                    flex: 1,
                    child: FlatButton(
                      child: Text(
                        'OK',
                        style: MyAppTheme.titlenearlyBlue16,
                      ),
                      onPressed: () {
                        Navigator.of(context).pop('ok');
                      },
                    )),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
